package shiyan2;

public class Course {
	String CourseName;
    int CourseId;
    Teacher teacher;
    float Credit;
    String Destination;
    String Time;
    Student[] students;
    Teacher[] teachers;
    
	String getDestination() {
		return Destination;
	}
	void setDestination(String destination) {
		Destination = destination;
	}
	
	String getTime() {
		return Time;
	}
	void setTime(String time) {
		Time = time;
	}
	
    Course(int courseId,String courseName,String destination,String time) {
        super();
        this.CourseId=courseId;
        this.CourseName=courseName;
        students = new Student[5];
        teachers = new Teacher[1];
        this.setDestination(destination);
        this.setTime(time);
    }

    Course() {
        super();
        students = new Student[5];
        teachers = new Teacher[1];
    }
    public String toString() {
    	return "老师学生选课如下：\n";
    }
    
    void setId(int id){
        this.CourseId=id;
    }
    int getId(){
        return this.CourseId;
    }
    void setName(String name){
        this.CourseName=name;
    }
    String getName(){
        return this.CourseName;
    }
    void setCredit(float credit ){
        this.Credit=credit;
    }
    float getCredit(){
        return this.Credit;
    }
    Teacher getTeacher() {
        return teacher;
    }
    void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }	         
    
    boolean SelectedStudent(Student stu){
        boolean cnt=false;
        for(Student s:students){
            if(s==stu){
                cnt=true;
                break;
            }
        }
        return cnt;
    }
    boolean SelectedTeacher(Teacher tea){
        boolean cnt=false;
        for(Teacher t:teachers){
            if(t==tea){
                cnt=true;
                break;
            }
        }
        return cnt;
    }

    boolean NullStudent(Student stu){
        boolean cnt=false;
        for(Student s:students){
            if(s==null){  
                cnt=true;
                break;
            }
        }
        return cnt;
    }
    
    boolean NullTeacher(Teacher tea){
        boolean cnt=false;
        for(Teacher t:teachers){
            if(t==null){
                cnt=true;
                break;
            }
        }
        return cnt;
    } 
    
    boolean addStudent(Student stu){
        boolean cnt = false;          
        if(!SelectedStudent(stu)&&NullStudent(stu)){
            for(int i=0;i<students.length;i++){
                if(students[i]==null){
                    students[i]=stu;
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    boolean addTeacher(Teacher tea){
        boolean cnt = false;        
        if(!SelectedTeacher(tea)&&NullTeacher(tea)){
            for(int i=0;i<teachers.length;i++){
                if(teachers[i]==null){
                    teachers[i]=tea;
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    boolean removeStudent(Student stu){
        boolean cnt=false;
        if(SelectedStudent(stu)){
            for(int i=0;i<students.length;i++){
                if(students[i]==stu){
                    students[i]=null;
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
    void displayStudent(){
        System.out.println("选"+this.CourseName+"的学生有:");
        for(Student s:students){
            if(s!=null){
                System.out.print(s.getStuName()+" ");
            }
        }
        System.out.println();
    }

}
